package LeetCode.tree;

import java.util.Arrays;

public class NC_45 {
    public static void main(String[] args) {
        NC_45 n = new NC_45();
        TreeNode root = TreeNode.createTree1();
        int[][] array = n.threeOrders(root);
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                System.out.print(array[i][j] + " ");
            }
        }
    }
    public int[][] threeOrders (TreeNode root) {
        int[][] arrays = new int[3][];
        first(root,arrays[0],0);
        // write code here
        return arrays;
    }
    public void first(TreeNode root,int[] arr,int i){
        if(root == null){
            return ;
        }
        if(i >= arr.length){
            arr = Arrays.copyOf(arr,arr.length+1);
        }
        arr[i] = root.val;
        i++;
        first(root.left,arr,i);
        first(root.right,arr,i);
    }
}
